/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.neolokura.travian.helper.bo.page;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

/**
 *
 * @author gustavo
 */
public class LoginPageObject extends PageObject {

    HtmlTextInput userName;
    HtmlPasswordInput password;
    HtmlForm form;

    public LoginPageObject(HtmlPage page) {
        super(page);

        try {
            form = page.getFormByName("snd");
        } catch (Exception e) {
            for (HtmlForm htmlForm : page.getForms()) {
                form = htmlForm;
            }
        }
        super.setSubmitButton(form.getButtonByName("s1"));
    }

    public HtmlPasswordInput getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if (password != null) {
            this.password = form.getInputByName("password");
            this.password.setValueAttribute(password);
        }
    }

    public HtmlTextInput getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        if (userName != null) {
            this.userName = form.getInputByName("name");
            this.userName.setValueAttribute(userName);
        }
    }
}
